package com.zhangsr.zus.remoting.api.transport.dispatcher;

import com.zhangsr.zus.common.URL;
import com.zhangsr.zus.remoting.api.ChannelHandler;
import com.zhangsr.zus.remoting.api.exchange.support.header.HeartbeatHandler;
import com.zhangsr.zus.remoting.api.transport.MultiMessageHandler;

/**
 * @Author: zhangsr
 */
public class ChannelHandlers {

    public static ChannelHandler wrap(ChannelHandler handler, URL url) {
        return ChannelHandlers.getInstance().wrapInternal(handler, url);
    }

    protected ChannelHandlers() {
    }

    protected ChannelHandler wrapInternal(ChannelHandler handler, URL url) {
        return new MultiMessageHandler(new HeartbeatHandler(handler));
    }

    private static ChannelHandlers INSTANCE = new ChannelHandlers();

    protected static ChannelHandlers getInstance() {
        return INSTANCE;
    }

    static void setTestingChannelHandlers(ChannelHandlers instance) {
        INSTANCE = instance;
    }
}